package comm.forms;



import comm.util.BitOperator;
import comm.util.TimeUtil;

import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.Date;

public class FunAnalysisForm {
    public void FunAnalysisFormView(String data) {
        //子窗体
        JFrame Jameson = new JFrame("首页-解析");
        Jameson.setSize(850, 500);
        Jameson.setLocationRelativeTo(null);


        //原始数据
        final TextArea taoriginalData = new TextArea(data, 0, 0, TextArea.SCROLLBARS_VERTICAL_ONLY);
        taoriginalData.setBounds(10, 20, 800, 100);

        JPanel jPoriginal = new JPanel();
        jPoriginal.setBorder(BorderFactory.createTitledBorder("原始数据"));
        jPoriginal.setBounds(5, 5, 820, 130);
        jPoriginal.setLayout(null);
        jPoriginal.add(taoriginalData);

        final TextArea taanalysis = new TextArea(null, 0, 0, TextArea.SCROLLBARS_VERTICAL_ONLY);
        taanalysis.setEditable(false);
        taanalysis.setFont(new Font(Font.DIALOG, Font.PLAIN, 13));
        taanalysis.setText("解析后的数据如下：\n" + AnalysisResult(taoriginalData.getText()));
        taanalysis.setBounds(10, 20, 800, 190);

        JPanel jPanalysis = new JPanel();
        jPanalysis.setBorder(BorderFactory.createTitledBorder("解析数据"));
        jPanalysis.setBounds(5, 200, 820, 220);
        jPanalysis.setLayout(null);
        jPanalysis.add(taanalysis);

        JPanel panel = new JPanel();
        Jameson.setVisible(true);

        Jameson.add(jPoriginal);
        Jameson.add(jPanalysis);
        Jameson.add(panel);
    }


    //解析:消息ID
    private static String AnalysisResult(String info) {
        try {
            StringBuilder SbData = new StringBuilder();
            if (info.substring(0, 2).equalsIgnoreCase("7E") &&
                    info.substring(info.length() - 2).equalsIgnoreCase("7E")) {


                boolean subPacket = false;
                SbData.append("消息ID：").append(info, 2, 6).append(",");
                // 目前有点问题，暂时未处理  out的问题
                SbData.append(GetMsgAttribute(info.substring(6, 10), false));
                SbData.append("设备号：").append(info, 10, 22).append(",");
                SbData.append("流水号：").append(info, 22, 26).append(",");

                switch (info.substring(2, 6)) {
                    ///命令协议解析
                    case "0001":
                        //终端通用应答   已测试
                        SbData.append("终端通用应答0001消息体：").append(DeviceGeneralReply(info));
                        break;
                    case "0002":
                        //终端心跳      已测试
                        SbData.append("终端心跳0002消息体：").append(DeviceHeart());
                        break;
                    case "0100":
                        //终端注册      已测试
                        SbData.append("终端注册0100消息体：").append(DeviceRegister(info, subPacket));
                        break;
                    case "0200":
                        //GPS位置信息   已测试
                        SbData.append("GPS位置信息0200消息体：").append(HandlePositionData(info));
                        break;
                    case "0091":
                        //依迅私有 升级结果应答   待测试
                        SbData.append("0091消息体：").append(DeviceUpdateResult(info));
                        break;
                    case "8624":
                        //黑车稽查指令下发      待测试
                        SbData.append("黑车稽查指令下发8624消息体:").append(BlackCarInspection(info));
                        break;
//                    case "8E20":
//                        //人脸对比结果下发
//                        SbData.append("人脸对比结果下发(8E20)消息体：" + FaceContrastResult(info));
//                        break;
                    case "8E21":
                        //人脸库下发   待测试
                        SbData.append("人脸库下发8E21消息体：").append(FaceDataBaseSet(info));
                        break;
                    case "1210":
                        //报警附件信息消息  待测试
                        SbData.append("报警附件信息消息1210消息体：").append(AlarmAnnexMessage(info));
                        break;
                    case "1212":
                        //文件上传完成消息  待测试
                        SbData.append("文件上传完成消息1212消息体：").append(FileUploadComplete(info));
                        break;
                    case "0702":
                        //采集驾驶员身份信息参数     待测试
                        SbData.append("采集驾驶员身份信息参数0702,消息体：").append(DirverInfoUpLoad(info));
                        break;
                    case "0704":
                        //盲点补传    待测试
                        SbData.append("盲点补传0704,消息体：").append(BlindUpLoad0704(info, subPacket));
                        break;
                    default:
                        SbData.append("消息体：").append(info.substring(2, 6));
                        break;
                }
                return SbData.toString();
            } else {
                JOptionPane.showMessageDialog(null,
                        "输入的数据非808数据，请检查后，重新输入！！！！！！",
                        "提示", JOptionPane.ERROR_MESSAGE);
                return SbData.toString();
            }
        } catch (Exception e) {
            return "解析出问题了,报错信息如下:" + e.toString();
        }
    }

    //消息体长度，是否有分包，加密，多媒体
    public static String GetMsgAttribute(String info, Boolean subPacket) {
        String ret = "";
        subPacket = false;
//        String s = Convert.ToString(HexToInt(info), 2);
        String s = Integer.toString(BitOperator.hexToInt(info), 2);
        while (s.length() < 16) {
            s = "0" + s;
        }
//        if (s[0] == '1')
        if (s.charAt(0) == '1') {
            ret += "多媒体标识:True,";
        }
        if (s.charAt(2) == '1') {
            ret += "分包标识:True,";
            subPacket = true;
        }
        if (s.charAt(5) == '1') {
            ret += "加密标识:True,";
        }
        ret += "消息体长度:" + Integer.parseInt(s.substring(6), 2) + ",";
        return ret;
    }


    //终端通用应答
    public static String DeviceGeneralReply(String info) {
        String data = info.substring(26);
        String CommandID = data.substring(4, 8);
        int ret = Integer.parseInt(data.substring(8, 10));
        String SRet = "";
        switch (ret) {
            case 0:
                SRet = "成功";
                break;
            case 1:
                SRet = "失败";
                break;
            case 2:
                SRet = "消息有误";
                break;
            case 3:
                SRet = "不支持";
                break;
        }
        return ("终端通用应答：" + GetDescriptionByCommandID(CommandID) + "，设备应答结果：" + SRet);
    }

    //终端心跳
    public static String DeviceHeart() {
        return "终端心跳";
    }

    //终端注册
    public static String DeviceRegister(String info, boolean subPacket) {
        String data = "";
        if (subPacket)
            data = info.substring(34, info.length() - 38);
        else
            data = info.substring(26, 26 + info.length() - 30);
        String ProvincialTerritory = Integer.toString(BitOperator.hexToInt(data.substring(0, 4)));
        String CityCountyTerritory = Integer.toString(BitOperator.hexToInt(data.substring(4, 4 * 2)));
        String Manufacturer = BitOperator.hexStringToString(data.substring(8, 18));
        String DevicemodelNumber = BitOperator.hexStringToString(data.substring(18, 16 + 24));
        String DeviceID = BitOperator.hexStringToString(data.substring(34 + 24, 72));
        String PlateColor = data.substring(48 + 24, 74);
        String PlateNumber = BitOperator.hexStringToString(data.substring(50 + 24));
        return "省域ID：" + ProvincialTerritory + "市县域ID：" + CityCountyTerritory + "制造商ID：" + Manufacturer +
                ",终端型号：" + DevicemodelNumber + ",终端ID:" + DeviceID + ",车牌颜色：" + PlateColor + ",车牌：" + PlateNumber + "";
    }


    //位置信息汇报
    public static String HandlePositionData(String info) {
        StringBuilder ret = new StringBuilder();
        String data = info.substring(26, 26 + info.length() - 30);
        //报警标志
        String AlarmSign = BitOperator.hexToBin(data.substring(0, 8), 32);
        ret.append("\n报警类型：");
        if (AlarmSign.charAt(31) == '1') ret.append("紧急报警,");
        if (AlarmSign.charAt(30) == '1') ret.append("超速报警,");
        if (AlarmSign.charAt(29) == '1') ret.append("疲劳驾驶,");
        if (AlarmSign.charAt(28) == '1') ret.append("危险预警,");
        if (AlarmSign.charAt(27) == '1') ret.append("GNSS模块发生故障,");
        if (AlarmSign.charAt(26) == '1') ret.append("GNSS天线未接或被剪断,");
        if (AlarmSign.charAt(25) == '1') ret.append("GNSS天线短路,");
        if (AlarmSign.charAt(24) == '1') ret.append("终端主电源欠压,");
        if (AlarmSign.charAt(23) == '1') ret.append("终端主电源掉电,");
        if (AlarmSign.charAt(22) == '1') ret.append("终端LCD或显示器故障,");
        if (AlarmSign.charAt(21) == '1') ret.append("TTS模块故障,");
        if (AlarmSign.charAt(20) == '1') ret.append("摄像头故障,");
        if (AlarmSign.charAt(19) == '1') ret.append("道路运输证 IC 卡模块故障");
        if (AlarmSign.charAt(18) == '1') ret.append("超速预警");
        if (AlarmSign.charAt(17) == '1') ret.append("疲劳驾驶报警,");
        if (AlarmSign.charAt(15) == '1') ret.append("SD卡异常");
        if (AlarmSign.charAt(13) == '1') ret.append("当天累计驾驶超时");
        if (AlarmSign.charAt(12) == '1') ret.append("超时停车");
        if (AlarmSign.charAt(11) == '1') ret.append("进出区域");
        if (AlarmSign.charAt(10) == '1') ret.append("进出路线");
        if (AlarmSign.charAt(9) == '1') ret.append("路段行驶时间不足/过长");
        if (AlarmSign.charAt(8) == '1') ret.append("路线偏离报警");
        if (AlarmSign.charAt(7) == '1') ret.append("车辆 VSS 故障");
        if (AlarmSign.charAt(6) == '1') ret.append("车辆油量异常");
        if (AlarmSign.charAt(5) == '1') ret.append("车辆被盗(通过车辆防盗器)");
        if (AlarmSign.charAt(4) == '1') ret.append("车辆非法点火");
        if (AlarmSign.charAt(3) == '1') ret.append("车辆非法位移");
        if (AlarmSign.charAt(2) == '1') ret.append("碰撞预警");
        if (AlarmSign.charAt(1) == '1') ret.append("侧翻预警");
        if (AlarmSign.charAt(0) == '1') ret.append("非法开门报警（终端未设置区域时，不判断非法开门）");


        //状态位
        String StateValue = BitOperator.hexToBin(data.substring(8, 16), 32);
        ret.append("\n状态：");
        if (StateValue.charAt(31) == '1') ret.append("ACC开,");
        else ret.append("ACC关,");
        if (StateValue.charAt(30) == '1') ret.append("定位,");
        else ret.append("未定位,");
        if (StateValue.charAt(29) == '1') ret.append("南纬,");
        else ret.append("北纬,");
        if (StateValue.charAt(28) == '1') ret.append("西经,");
        else ret.append("东经,");
        if (StateValue.charAt(27) == '1') ret.append("停运状态,");
        else ret.append("运营状态,");
        if (StateValue.charAt(26) == '1') ret.append("经纬度加密,");
        else ret.append("经纬度未加密,");
        if (StateValue.charAt(23) == '1') ret.append("半载,");
        else ret.append("查看表25状态位定义查看对用取值：").append(StateValue.charAt(23)).append("《--》提示：00：空车；01：半载；10：保留；11：满载,");

        if (StateValue.charAt(21) == '1') ret.append("油路断开,");
        else ret.append("油路正常,");
        if (StateValue.charAt(20) == '1') ret.append("电路断开,");
        else ret.append("电路正常,");
        if (StateValue.charAt(19) == '1') ret.append("车门加锁,");
        else ret.append("车门解锁,");
        if (StateValue.charAt(18) == '1') ret.append("门磁开,");
        else ret.append("门磁关,");
        if (StateValue.charAt(17) == '1') ret.append("后门开,");
        else ret.append("后门关,");
        if (StateValue.charAt(16) == '1') ret.append("发动机开,");
        else ret.append("发动机关,");
        if (StateValue.charAt(15) == '1') ret.append("空调开,");
        else ret.append("空调关,");
        if (StateValue.charAt(14) == '1') ret.append("刹车,");
        else ret.append("未刹车,");
        if (StateValue.charAt(13) == '1') ret.append("左转开，");
        else ret.append("左转关，");
        if (StateValue.charAt(12) == '1') ret.append("右转开，");
        else ret.append("右转关，");
        if (StateValue.charAt(11) == '1') ret.append("远光开，");
        else ret.append("远光关，");
        if (StateValue.charAt(10) == '1') ret.append("近光开，");
        else ret.append("近光关，");
        if (StateValue.charAt(9) == '1') ret.append("顶盖已密闭，");
        else ret.append("顶盖未密闭，");
        if (StateValue.charAt(8) == '1') ret.append("箱体已举升,");
        else ret.append("箱体未举升，");
        if (StateValue.charAt(6) == '1') ret.append("箱体已举升,");
        else ret.append("箱体未举升，");
        if (StateValue.charAt(5) == '0') ret.append("举起，");
        else ret.append("未举起，");
//        if (StateValue.charAt(2) == '1') ret += "洒水清扫中，";
//        else ret += "未扫水清扫，";
        ret.append("\nGPS信息：纬度：").append(BitOperator.hexToInt(data.substring(16, 24)) / 1000000.0).append(",");
        ret.append("经度：").append(BitOperator.hexToInt(data.substring(24, 32)) / 1000000.0).append(",");
        ret.append("高度：").append(BitOperator.hexToInt(data.substring(32, 36))).append(",");
        ret.append("速度：").append((int) (BitOperator.hexToInt(data.substring(36, 40)) / 10.0)).append(",");
        ret.append("方向：").append(BitOperator.hexToInt(data.substring(40, 44))).append(",");
        Date gpsDate = TimeUtil.getDateByFormat(data.substring(44, 56), TimeUtil.dateFormatyyMMddHHmmss);
        ret.append("时间：").append(TimeUtil.getStringByFormat(gpsDate, TimeUtil.dateFormatYMDHMS));

        //附加信息定义
        data = data.substring(56);
        String TempStr = "";
        ret.append("\n附加信息:");
        {
            String tmp = "";
            while (data.length() > 0) {
                if (data.length() < 2) {
                    break;
                }
                TempStr = data.substring(0, 2);

                switch (TempStr) {
                    case "01":
                        //里程，对应车上里程表读数  里程，DWORD，1/10km，对应车上里程表读数
                        tmp = data.substring(4, (BitOperator.hexToInt(data.substring(2, 4))) * 3);
                        ret.append("里程：").append(BitOperator.hexToInt(tmp) * 100);
                        //s = s + "里程：" + attach.Mileage.ToString() + "米 ";
                        break;
                    case "02":
                        //油量，对应车上油量表读数
                        tmp = data.substring(4, (BitOperator.hexToInt(data.substring(2, 4))) * 3);
                        if (!tmp.isEmpty())
                            ret.append("油量：").append(BitOperator.hexToInt(tmp) / 10.0);
                        //s = s + "油量：" + attach.OilMass.ToString() + "升 ";
                        break;
                    case "03":
                        //行驶记录功能获取的速度
                        tmp = data.substring(4, (BitOperator.hexToInt(data.substring(2, 4))) * 3);
                        ret.append("行驶记录仪速度：").append((int) (BitOperator.hexToInt(tmp) / 10.0));
                        break;
                    case "04":
                        //转鼓状态：首字节=正反转，1为正转，0为反转；后两字节表示转速，单位：100ms/圈
                        tmp = data.substring(4, (BitOperator.hexToInt(data.substring(2, 4))) * 3);
                        int hexing = BitOperator.hexToInt(tmp);
                        if (hexing == '1') {
                            ret.append("转鼓状态：正转");
                        } else {
                            ret.append("转鼓状态：反转");
                        }
                        ret.append(data.substring((BitOperator.hexToInt(data.substring(2, 4))) * 4, 0)).append("ms/圈");
                        break;
                    case "11":
                        //超速报警附加信息
                        tmp = data.substring(4, (BitOperator.hexToInt(data.substring(2, 4))) * 4);
                        ret.append("超速报警：").append(BitOperator.hexToInt(tmp));
                        break;
                    case "12":
                        //进出区域/路线报警附加信息
                        int Type = BitOperator.hexToInt(data.substring(4, 6));
                        if (Type == 1) {
                            ret.append("进出区域/路线报警附加信息(位置类型:圆型区域,");
                        } else if (Type == 2) {
                            ret.append("进出区域/路线报警附加信息(位置类型:矩形区域,");
                        } else if (Type == 3) {
                            ret.append("进出区域/路线报警附加信息(位置类型:多边形区域,");
                        } else if (Type == 4) {
                            ret.append("进出区域/路线报警附加信息(位置类型:路线,");
                        }
                        ret.append("区域或路线ID:").append(BitOperator.hexToInt(data.substring(6, 16)));
                        int Direction = BitOperator.hexToInt(data.substring(16));
                        if (Direction == 0) {
                            ret.append("方向为进)");
                        } else if (Direction == 1) {
                            ret.append("方向为出)");
                        }
                        break;
                    case "13":
                        //路段行驶时间不足/过长报警附加信
                        ret.append("路段行驶时间不足/过长报警附加信息(路段ID:").append(BitOperator.hexToInt(data.substring(4, 12))).append("路段行驶时间:").append(BitOperator.hexToInt(data.substring(12, 20)));
                        int result = BitOperator.hexToInt(data.substring(20));
                        if (result == 0) {
                            ret.append("结果:不足)");
                        } else if (result == 1) {
                            ret.append("结果:过长)");
                        }
                        break;
                    case "14":
                        //1078协议视频报警
//                            gps.setVam(Long.parseLong(attachContent.substring(0,8),16));
//                        gps.SetAlarm(GpsAlarmType.storageUnitFailure);
//                        tmp = data.substring(4, (BitOperator.hexToInt(data.substring(2, 4))) * 2);
                        ret.append("存储单元故障报警:").append(BitOperator.hexToInt(data.substring(4, 12))).append(",");
                        break;
                    case "25":
                        //新北斗 扩展车辆信号状态位
                        tmp = data.substring(4, (BitOperator.hexToInt(data.substring(2, 4))) * 3);
                        String bin = BitOperator.hexToBin(tmp, 32);
                        if (Integer.parseInt(Character.toString(bin.charAt(31))) == 1)
                            ret.append("近光开,");
                        if (Integer.parseInt(Character.toString(bin.charAt(31 - 1))) == 1)
                            ret.append("远光开,");
                        if (Integer.parseInt(Character.toString(bin.charAt(31 - 2))) == 1)
                            ret.append("右转开，");
                        if (Integer.parseInt(Character.toString(bin.charAt(31 - 3))) == 1)
                            ret.append("左转开，");
                        if (Integer.parseInt(Character.toString(bin.charAt(31 - 4))) == 1)
                            ret.append("刹车开,");
                        if (Integer.parseInt(Character.toString(bin.charAt(31 - 5))) == 1)
                            ret.append("倒车开,");
                        if (Integer.parseInt(Character.toString(bin.charAt(31 - 6))) == 1)
                            ret.append("雾灯开,");
                        if (Integer.parseInt(Character.toString(bin.charAt(31 - 7))) == 1)
                            ret.append("示廓开,");
                        if (Integer.parseInt(Character.toString(bin.charAt(31 - 8))) == 1)
                            ret.append("喇叭信号开,");
                        if (Integer.parseInt(Character.toString(bin.charAt(31 - 9))) == 1)
                            ret.append("空调开,");
                        if (Integer.parseInt(Character.toString(bin.charAt(31 - 10))) == 1)
                            ret.append("空挡开,");
                        if (Integer.parseInt(Character.toString(bin.charAt(31 - 11))) == 1)
                            ret.append("缓速器正常,");
                        if (Integer.parseInt(Character.toString(bin.charAt(31 - 12))) == 1)
                            ret.append("ABS工作正常,");
                        if (Integer.parseInt(Character.toString(bin.charAt(31 - 13))) == 1)
                            ret.append("加热器工作正常,");
                        if (Integer.parseInt(Character.toString(bin.charAt(31 - 14))) == 1)
                            ret.append("离合器状态正常,");
                        break;
                    case "2A":
                        tmp = data.substring(4, 6);
                        String bin1 = BitOperator.hexToBin(tmp, 15);
                        if (Integer.parseInt(Character.toString(bin1.charAt(15))) == 1)
                            ret.append("深度休眠状态,");
                        if (Integer.parseInt(Character.toString(bin1.charAt(15 - 1))) == 1)
                            ret.append("休眠状态,");
                        break;
                    case "30":
                        //buty，无线通信网络信号强度  长度1
                        tmp = data.substring(4, 6);
                        ret.append("无限通信网络信号强度：").append(BitOperator.hexToInt(tmp));
                        break;
                    case "31":
                        //buty，GNSS定位卫星数   长度1
                        tmp = data.substring(4, 6);
                        ret.append("GNSS定位卫星数：").append(BitOperator.hexToInt(tmp));
                        break;
                    case "E0":
                        //油耗
                        //油耗类型
                        int OilConsumption = BitOperator.hexToInt(data.substring(4, 6));
                        if (OilConsumption == 0) {
                            ret.append("油耗类型:电阻式值:").append(BitOperator.hexToInt(data.substring(6, 10))).append(".").append(BitOperator.hexToInt(data.substring(10, 12)));
                        } else if (OilConsumption == 1) {
                            ret.append("油耗类型:电压式值:").append(BitOperator.hexToInt(data.substring(6, 8))).append(".").append(BitOperator.hexToInt(data.substring(8, 16)));
                        } else if (OilConsumption == 2) {
                            ret.append("油耗类型:液位值:").append(BitOperator.hexToInt(data.substring(4, 12))).append("mm,");
                        }
                        break;
                    case "E8":
                        //重量传感器值,当值为0xFFFF时表示没有重量回传
                        tmp = data.substring(4, (BitOperator.hexToInt(data.substring(2, 4))) * 2);
                        ret.append("传感器原始值：").append(BitOperator.hexToInt(tmp.substring(0, 4))).append(",传感器状态值：").append(tmp.substring(4, 6)).append(",顶灯状态：");
                        switch (tmp.substring(6, 8)) {
                            case "00":
                                ret.append("熄灭,");
                                break;
                            case "01":
                                ret.append("绿灯,");
                                break;
                            case "02":
                                ret.append("黄灯,");
                                break;
                            case "04":
                                ret.append("红灯,");
                                break;
                        }
                        ret.append("传感器速度：").append(BitOperator.hexToInt(tmp.substring(8, 10))).append(".").append(BitOperator.hexToInt(tmp.substring(10, 12))).append(",");
                        break;
                    case "EB":
                        //小书包 定位模式上报
                        int state = BitOperator.hexToInt(data.substring(6, 8));
                        if (state == 1) {
                            ret.append("当前为充电状态,剩余电量:").append(BitOperator.hexToInt(data.substring(4, 6)));
                        } else if (state == 2) {
                            ret.append("当前为未充电状态,剩余电量:").append(BitOperator.hexToInt(data.substring(4, 6)));
                        }
                        break;
                    case "EC":
                        //小书包
                        //长度: 2 类型: WORD
                        //第一个字节平台设置定位模式
                        //1.基站定位； 2.普通定位； 3.高精度定位
                        //第二个字节当前定位器定位状态
                        //1：基站定位；2：WIFI定位； 3：GPS定位 4：高精度RTK
                        int Mode = BitOperator.hexToInt(data.substring(4, 6));
                        int LocationState = BitOperator.hexToInt(data.substring(6, 8));
                        if (Mode == 1) {
                            ret.append("定位模式:基站定位,");
                        } else if (Mode == 2) {
                            ret.append("定位模式:普通定位,");
                        } else if (Mode == 3) {
                            ret.append("定位模式:高精度定位,");
                        }

                        if (LocationState == 1) {
                            ret.append("定位状态:基站定位,");
                        } else if (LocationState == 2) {
                            ret.append("定位状态:WIFI定位,");
                        } else if (LocationState == 3) {
                            ret.append("定位状态:GPS定位,");
                        } else if (LocationState == 4) {
                            ret.append("定位状态:高精度RTK,");
                        }
                        break;
                    case "EF":
                        //小书包 电池电压
                        tmp = data.substring(4, 8);
                        ret.append("当前定位器电池电压:").append(BitOperator.hexToInt(tmp)).append("mV,");
                    case "E1":
                        ret.append("扩展信息E1未解析,");
                        break;
                    case "F1":
                        //油量传感器值
                        int OilStatus = BitOperator.hexToInt(data.substring(4, 6));
                        if (OilStatus == 0) {
                            ret.append("油量状态为实时数据,油量传感器读取值:").append(BitOperator.hexToInt(data.substring(6, 8)));
                        } else if (OilStatus == 1) {
                            ret.append("油量状态为快速增加").append(BitOperator.hexToInt(data.substring(6, 8)));
                        } else if (OilStatus == 2) {
                            ret.append("油量状态为快速减少").append(BitOperator.hexToInt(data.substring(6, 8)));
                        } else if (OilStatus == 3) {
                            ret.append("油量状态为平行震荡").append(BitOperator.hexToInt(data.substring(6, 8)));
                        }
                        break;
                    case "64":
                        //苏标协议 高级驾驶辅助系统报警信息
//                        tmp = data.substring(10, 12);
//                        String AlarmType = "";
//                        int FrontCarSpeed = 0;
//                        int FrontCarDistance = 0;
//                        String TmpDeviateType = data.substring(20, 22);
//                        String DeviateType = "";
//                        String ReasonSigntype = "";
//
//                        if (tmp == "01") {
//                            AlarmType = "前向碰撞报警";
//                            FrontCarSpeed = BitOperator.hexToInt(data.substring(16, 18));
//                            FrontCarDistance = BitOperator.hexToInt(data.substring(18, 20));
//                        }
//                        if (tmp == "02") {
//                            AlarmType = "车道偏离报警";
//                            FrontCarSpeed = BitOperator.hexToInt(data.substring(16, 18));
//                            FrontCarDistance = BitOperator.hexToInt(data.substring(18, 20));
//                            if (TmpDeviateType == "01") {
//                                DeviateType = "左侧偏离,";
//                            } else if (TmpDeviateType == "02") {
//                                DeviateType = "右侧偏离,";
//                            }
//                        }
//                        if (tmp == "03")
//                            AlarmType = "车距过近报警";
//                        if (tmp == "04") {
//                            AlarmType = "行人碰撞报警";
//                            FrontCarDistance = BitOperator.hexToInt(data.substring(18, 20));
//                        }
//                        if (tmp == "05")
//                            AlarmType = "频繁变道报警";
//                        if (tmp == "06") {
//                            AlarmType = "道路标识超限报警";
//                            tmp = data.substring(22, 24);
//                            if (tmp == "01") {
//                                ReasonSigntype = "限速标志,";
//                            } else if (tmp == "02") {
//                                ReasonSigntype = "限高标志,";
//                            } else if (tmp == "03") {
//                                ReasonSigntype = "限重标志";
//                            }
//                        }
//                        if (tmp == "07")
//                            AlarmType = "障碍物报警";
//                        if (tmp == "10") {
//                            AlarmType = "道路标志识别事件";
//                            tmp = data.substring(22, 24);
//                            if (tmp == "01") {
//                                ReasonSigntype = "限速标志,";
//                            } else if (tmp == "02") {
//                                ReasonSigntype = "限高标志,";
//                            } else if (tmp == "03") {
//                                ReasonSigntype = "限重标志";
//                            }
//                        }
//                        if (tmp == "11")
//                            AlarmType = "主动抓拍事件";
//
//                        String tmpAlarmLevel = data.substring(12, 14);
//                        String AlarmLevel = "";
//                        if (tmpAlarmLevel.equals(01)) {
//                            AlarmLevel = "一级报警";
//                        } else if (tmpAlarmLevel.equals(02)) {
//                            AlarmLevel = "二级报警";
//                        }
//
//
//                        if (DeviateType == "01") {
//                            DeviateType = "";
//                        } else if (DeviateType == "02") {
//                            DeviateType = "";
//                        }
//
//                        //车辆状态
//                        BitOperator.hexToInt(data.substring(60, 64));
//
//                        //报警标识号
//                        BitOperator.hexToInt(data.substring(64));
//
//                        Date gpsdate = TimeUtil.getDateByFormat(data.substring(48, 60), TimeUtil.dateFormatyyMMddHHmmss);
//                        ret += "高级驾驶辅助系统报警信息:(报警ID:" + BitOperator.hexToInt(data.substring(4, 8)) + "标志状态:"
//                                + BitOperator.hexToInt(data.substring(8, 10)) + ",报警/事件类型:" + AlarmType + "报警级别:"
//                                + AlarmLevel + "前车速度:" + BitOperator.hexToInt(data.substring(14, 16)) + "Km/h,前车/行人距离" +
//                                FrontCarSpeed + "Km/h,前车/行人距离:" + FrontCarDistance + "ms,偏离类型:" + DeviateType + "道路标志识别类型:"
//                                + ReasonSigntype + "道路标志识别数据:" + BitOperator.hexToInt(data.substring(24, 26)) + "车速:" +
//                                BitOperator.hexToInt(data.substring(26, 28)) + "Km/h,高程:" + BitOperator.hexToInt(data.substring(28, 32))
//                                + "m,纬度:" + BitOperator.hexToInt(data.substring(32, 40)) / 1000000.0 + "经度:" +
//                                BitOperator.hexToInt(data.substring(40, 48)) / 1000000.0 + "时间:" +
//                                TimeUtil.getStringByFormat(gpsdate, TimeUtil.dateFormatYMDHMS) + "车辆状态:暂时未解析,报警标识号:暂时未解析.";

                        tmp = data.substring(14, 16);
                        if (tmp.equals("01"))
                            ret.append("前向碰撞报警");
                        if (tmp.equals("02"))
                            ret.append("车道偏离报警");
                        if (tmp.equals("03"))
                            ret.append("车距过近报警");
                        if (tmp.equals("04"))
                            ret.append("行人碰撞报警");
                        if (tmp.equals("05"))
                            ret.append("频繁变道报警");
                        if (tmp.equals("06"))
                            ret.append("道路标识超限报警");
                        if (tmp.equals("07"))
                            ret.append("障碍物报警");
                        if (tmp.equals("10"))
                            ret.append("道路标志识别事件");
                        if (tmp.equals("11"))
                            ret.append("主动抓拍事件");
                        break;
                    case "65":
                        //苏标协议 驾驶员状态检测系统报警信息
                        tmp = data.substring(14, 16);
                        if (tmp.equals("01"))
                            ret.append("疲劳驾驶报警,");
                        if (tmp.equals("02"))
                            ret.append("接打电话报警,");
                        if (tmp.equals("03"))
                            ret.append("抽烟报警,");
                        if (tmp.equals("04"))
                            ret.append("分神驾驶报警,");
                        if (tmp.equals("05"))
                            ret.append("驾驶员异常报警,");
                        if (tmp.equals("10"))
                            ret.append("自动抓拍事件,");
                        if (tmp.equals("11"))
                            ret.append("驾驶员变更事件,");
                        break;
                    case "66":
                        //苏标协议 胎压检测系统报警信息
                        tmp = data.substring(14, 16);
                        if (tmp.equals("00"))
                            ret.append("胎压,");
                        if (tmp.equals("01"))
                            ret.append("胎压过高报警,");
                        if (tmp.equals("02"))
                            ret.append("胎压过底报警,");
                        if (tmp.equals("03"))
                            ret.append("胎温过高报警,");
                        if (tmp.equals("04"))
                            ret.append("传感器异常报警,");
                        if (tmp.equals("05"))
                            ret.append("胎压不平衡报警,");
                        if (tmp.equals("06"))
                            ret.append("慢漏气报警,");
                        if (tmp.equals("07"))
                            ret.append("电池电量低报警,");
                        break;
                    case "67":
                        //苏标协议 盲区检测系统报警信息
                        tmp = data.substring(14, 16);
                        if (tmp.equals("01"))
                            ret.append("后方接近报警");
                        if (tmp.equals("02"))
                            ret.append("左侧后方接近报警");
                        if (tmp.equals("03"))
                            ret.append("右侧后方接近报警");
                        break;

                    case "6A":
                        tmp = data.substring(14, 16);
                        if (tmp.equals("01"))
                            ret.append("车厢摄像头遮挡,");
                        if (tmp.equals("02"))
                            ret.append("货物检测未密闭(非传感器检测),");
                        if (tmp.equals("03"))
                            ret.append("货物检测异常举升（非传感器检测）,");
                        if (tmp.equals("03"))
                            ret.append("车厢摄像头角度偏离,");
                        break;
                    case "6B":
                        tmp = data.substring(14, 16);
                        if (tmp.equals("01"))
                            ret.append("前方盲区报警,");
                        if (tmp.equals("11"))
                            ret.append("右侧盲区一级报警),");
                        if (tmp.equals("12"))
                            ret.append("右侧盲区二级报警,");
                        if (tmp.equals("13"))
                            ret.append("右侧盲区三级报警,");
                        break;
                    default:
                        return ret.toString();
                }
                data = data.substring((BitOperator.hexToInt(data.substring(2, 4)) + 2) * 2);
            }
        }
        return ret.toString();
    }


    //依迅私有 升级结果应答
    public static String DeviceUpdateResult(String info) {
        String ret = "";
        String data = info.substring(26, 26 + info.length() - 30);
        //升级类型+版本号长度+版本号
        if (BitOperator.hexToInt(data.substring(0, 2)) == '0') {
            ret += "升级类型:mcu,版本号长度:" + BitOperator.hexToInt(data.substring(2, 4)) + "版本号:" + BitOperator.hexToInt(data.substring(4, BitOperator.hexToInt(data.substring(2, 4))));
        } else if (BitOperator.hexToInt(data.substring(0, 2)) == '1') {
            ret += "升级类型:系统固件,版本号长度:" + BitOperator.hexToInt(data.substring(2, 4)) + "版本号:" + BitOperator.hexToInt(data.substring(4, BitOperator.hexToInt(data.substring(2, 4))));
        } else {
            ret += "升级类型:app,版本号长度:" + BitOperator.hexToInt(data.substring(2, 4)) + "版本号:" + BitOperator.hexToInt(data.substring(4, BitOperator.hexToInt(data.substring(2, 4))));
        }
        //升级结果
        if (BitOperator.hexToInt(data.substring(BitOperator.hexToInt(data.substring(2, 4)), BitOperator.hexToInt(data.substring(2, 4)) + 2)) == '0') {
            ret += "升级结果:成功,";
        } else if (BitOperator.hexToInt(data.substring(BitOperator.hexToInt(data.substring(2, 4)), BitOperator.hexToInt(data.substring(2, 4)) + 2)) == '1') {
            ret += "升级结果:失败,";
        } else {
            ret += "升级结果:取消,";
        }
        //同步时间
        String SyncTime = data.substring(BitOperator.hexToInt(data.substring(2, 4)) + 2, BitOperator.hexToInt(data.substring(2, 4)) + 2 + 12);
        Date SyncTimeDate = TimeUtil.getDateByFormat(SyncTime, TimeUtil.dateFormatyyMMddHHmmss);
        ret += "同步时间：" + TimeUtil.getStringByFormat(SyncTimeDate, TimeUtil.dateFormatYMDHMS);
        //升级完成时间
        String CompleteTime = data.substring(BitOperator.hexToInt(data.substring(2, 4)) + 2 + 12, BitOperator.hexToInt(data.substring(2, 4)) + 2 + 12 + 12);
        Date CompleteTimeDate = TimeUtil.getDateByFormat(CompleteTime, TimeUtil.dateFormatyyMMddHHmmss);
        ret += "同步时间：" + TimeUtil.getStringByFormat(CompleteTimeDate, TimeUtil.dateFormatYMDHMS);
        return ret;
    }


    //黑车稽查
    public static String BlackCarInspection(String info) {
        String data = "";
        String ret = "";
        data = info.substring(26, 26 + info.length() - 30);
        ret += "中心点经度:" + BitOperator.hexToInt(data.substring(0, 8)) + "中心点纬:" + BitOperator.hexToInt(data.substring(8, 16)) +
                "距中心点距离:" + BitOperator.hexToInt(data.substring(16, 18)) + "开始时间:" +
                data.substring(16, 18);

        return ret;
    }


    //盲点补传
    public static String BlindUpLoad0704(String info, boolean subPacket) {
        String data = "";
        if (subPacket)
            data = info.substring(34, 34 + info.length() - 30);
        else
            data = info.substring(26, 26 + info.length() - 30);
        StringBuilder ret = new StringBuilder("定位数据批量上传");
        int count = BitOperator.hexToInt(data.substring(0, 4));
        ret.append("总数：").append(count);
        int type = BitOperator.hexToInt(data.substring(4, 6));
        if (type == 0)
            ret.append("，类型：正常位置批量汇报,");
        else if (type == 1)
            ret.append("，类型：盲区补报,");
        data = data.substring(6);

        for (int i = 0; i < count; i++) {
            int len = BitOperator.hexToInt(data.substring(0, 4));
            String d = data.substring(4, len * 2);
            ret.append(HandleOnePos(d));
            data = data.substring(4 + len * 2);
        }

        return ret.toString();
    }

    public static String HandleOnePos(String data) {
        StringBuilder ret = new StringBuilder();
        String AlarmSign = BitOperator.hexToBin(data.substring(0, 8), 32);
        ret.append("\n报警类型：\n");
        if (AlarmSign.charAt(31) == '1') ret.append("紧急报警,");
        if (AlarmSign.charAt(30) == '1') ret.append("超速报警,");
        if (AlarmSign.charAt(29) == '1') ret.append("疲劳驾驶,");
        if (AlarmSign.charAt(28) == '1') ret.append("危险预警,");
        if (AlarmSign.charAt(27) == '1') ret.append("GNSS模块发生故障,");
        if (AlarmSign.charAt(26) == '1') ret.append("GNSS天线未接或被剪断,");
        if (AlarmSign.charAt(25) == '1') ret.append("GNSS天线短路,");
        if (AlarmSign.charAt(24) == '1') ret.append("终端主电源欠压,");
        if (AlarmSign.charAt(23) == '1') ret.append("终端主电源掉电,");
        if (AlarmSign.charAt(22) == '1') ret.append("终端LCD或显示器故障,");
        if (AlarmSign.charAt(21) == '1') ret.append("TTS模块故障,");
        if (AlarmSign.charAt(20) == '1') ret.append("摄像头故障,");
        if (AlarmSign.charAt(19) == '1') ret.append("道路运输证 IC 卡模块故障");
        if (AlarmSign.charAt(18) == '1') ret.append("超速预警");
        if (AlarmSign.charAt(17) == '1') ret.append("疲劳驾驶报警,");
        if (AlarmSign.charAt(15) == '1') ret.append("SD卡异常");
        if (AlarmSign.charAt(13) == '1') ret.append("当天累计驾驶超时");
        if (AlarmSign.charAt(12) == '1') ret.append("超时停车");
        if (AlarmSign.charAt(11) == '1') ret.append("进出区域");
        if (AlarmSign.charAt(10) == '1') ret.append("进出路线");
        if (AlarmSign.charAt(9) == '1') ret.append("路段行驶时间不足/过长");
        if (AlarmSign.charAt(8) == '1') ret.append("路线偏离报警");
        if (AlarmSign.charAt(7) == '1') ret.append("车辆 VSS 故障");
        if (AlarmSign.charAt(6) == '1') ret.append("车辆油量异常");
        if (AlarmSign.charAt(5) == '1') ret.append("车辆被盗(通过车辆防盗器)");
        if (AlarmSign.charAt(4) == '1') ret.append("车辆非法点火");
        if (AlarmSign.charAt(3) == '1') ret.append("车辆非法位移");
        if (AlarmSign.charAt(2) == '1') ret.append("碰撞预警");
        if (AlarmSign.charAt(1) == '1') ret.append("侧翻预警");
        if (AlarmSign.charAt(0) == '1') ret.append("非法开门报警（终端未设置区域时，不判断非法开门）");


        //状态位
        String StateValue = BitOperator.hexToBin(data.substring(8, 16), 32);
        ret.append("\n状态：\n");
        if (StateValue.charAt(31) == '1') ret.append("ACC开,");
        else ret.append("ACC关,");
        if (StateValue.charAt(30) == '1') ret.append("定位,");
        else ret.append("未定位,");
        if (StateValue.charAt(29) == '1') ret.append("南纬,");
        else ret.append("北纬,");
        if (StateValue.charAt(28) == '1') ret.append("西经,");
        else ret.append("东经,");
        if (StateValue.charAt(27) == '1') ret.append("停运状态,");
        else ret.append("运营状态,");
        if (StateValue.charAt(26) == '1') ret.append("经纬度加密,");
        else ret.append("经纬度未加密,");
        if (StateValue.charAt(23) == '1') ret.append("半载,");
        else
            ret.append("半载状态,查看表25状态位定义查看对应取值：").append(StateValue.charAt(23)).append("《--》提示：00：空车；01：半载；10：保留；11：满载,");

        if (StateValue.charAt(21) == '1') ret.append("油路断开,");
        else ret.append("油路正常,");
        if (StateValue.charAt(20) == '1') ret.append("电路断开,");
        else ret.append("电路正常,");
        if (StateValue.charAt(19) == '1') ret.append("车门加锁,");
        else ret.append("车门解锁,");
        if (StateValue.charAt(18) == '1') ret.append("门磁开,");
        else ret.append("门磁关,");
        if (StateValue.charAt(17) == '1') ret.append("后门开,");
        else ret.append("后门关,");
        if (StateValue.charAt(16) == '1') ret.append("发动机开,");
        else ret.append("发动机关,");
        if (StateValue.charAt(15) == '1') ret.append("空调开,");
        else ret.append("空调关,");
        if (StateValue.charAt(14) == '1') ret.append("刹车,");
        else ret.append("未刹车,");
        if (StateValue.charAt(13) == '1') ret.append("左转开，");
        else ret.append("左转关，");
        if (StateValue.charAt(12) == '1') ret.append("右转开，");
        else ret.append("右转关，");
        if (StateValue.charAt(11) == '1') ret.append("远光开，");
        else ret.append("远光关，");
        if (StateValue.charAt(10) == '1') ret.append("近光开，");
        else ret.append("近光关，");
        if (StateValue.charAt(9) == '1') ret.append("顶盖已密闭，");
        else ret.append("顶盖未密闭，");
        if (StateValue.charAt(8) == '1') ret.append("箱体已举升,");
        else ret.append("箱体未举升，");
        if (StateValue.charAt(6) == '1') ret.append("箱体已举升,");
        else ret.append("箱体未举升，");
        if (StateValue.charAt(5) == '0') ret.append("举起，");
        else ret.append("未举起，");
//        if (StateValue.charAt(2) == '1') ret += "洒水清扫中，";
//        else ret += "未扫水清扫，";
        ret.append("\nGPS信息：\n纬度：").append(BitOperator.hexToInt(data.substring(16, 24)) / 1000000.0).append(",");
        ret.append("经度：").append(BitOperator.hexToInt(data.substring(24, 32)) / 1000000.0).append(",");
        ret.append("高度：").append(BitOperator.hexToInt(data.substring(32, 36))).append(",");
        ret.append("速度：").append((int) (BitOperator.hexToInt(data.substring(36, 40)) / 10.0)).append(",");
        ret.append("方向：").append(BitOperator.hexToInt(data.substring(40, 44))).append(",");
        Date gpsDate = TimeUtil.getDateByFormat(data.substring(44, 56), TimeUtil.dateFormatyyMMddHHmmss);
        ret.append("时间：").append(TimeUtil.getStringByFormat(gpsDate, TimeUtil.dateFormatYMDHMS));

        //附加信息定义
        data = data.substring(56);
        String TempStr = "";
        ret.append("\n附加信息:\n");
        {
            String tmp = "";
            while (data.length() > 0) {
                if (data.length() < 2) {
                    break;
                }
                TempStr = data.substring(0, 2);


                switch (TempStr) {
                    case "01":
                        //里程，对应车上里程表读数  里程，DWORD，1/10km，对应车上里程表读数
                        tmp = data.substring(4, (BitOperator.hexToInt(data.substring(2, 4))) * 3);
                        ret.append("里程：").append(BitOperator.hexToInt(tmp) * 100);
                        //s = s + "里程：" + attach.Mileage.ToString() + "米 ";
                        break;
                    case "02":
                        //油量，对应车上油量表读数
                        tmp = data.substring(4, (BitOperator.hexToInt(data.substring(2, 4))) * 4);
                        if (!tmp.isEmpty())
                            ret.append("油量：").append(BitOperator.hexToInt(tmp) / 10.0);
                        //s = s + "油量：" + attach.OilMass.ToString() + "升 ";
                        break;
                    case "03":
                        //行驶记录功能获取的速度
                        tmp = data.substring(4, (BitOperator.hexToInt(data.substring(2, 4))) * 4);
                        ret.append("行驶记录仪速度：").append((int) (BitOperator.hexToInt(tmp) / 10.0));
                        break;
                    case "04":
                        //转鼓状态：首字节=正反转，1为正转，0为反转；后两字节表示转速，单位：100ms/圈
                        tmp = data.substring(4, (BitOperator.hexToInt(data.substring(2, 4))) * 4);
                        int hexint = BitOperator.hexToInt(tmp);
                        if (hexint == '1') {
                            ret.append("转鼓状态：正转");
                        } else {
                            ret.append("转鼓状态：反转");
                        }
                        ret.append(data.substring((BitOperator.hexToInt(data.substring(2, 4))) * 4, 0)).append("ms/圈");
                        break;
                    case "11":
                        //超速报警附加信息
                        tmp = data.substring(4, (BitOperator.hexToInt(data.substring(2, 4))) * 4);
                        ret.append("超速报警：").append(BitOperator.hexToInt(tmp));
                        break;
                    case "12":
                        //进出区域/路线报警附加信息
                        int Type = BitOperator.hexToInt(data.substring(4, 6));
                        if (Type == 1) {
                            ret.append("进出区域/路线报警附加信息(位置类型:圆型区域,");
                        } else if (Type == 2) {
                            ret.append("进出区域/路线报警附加信息(位置类型:矩形区域,");
                        } else if (Type == 3) {
                            ret.append("进出区域/路线报警附加信息(位置类型:多边形区域,");
                        } else if (Type == 4) {
                            ret.append("进出区域/路线报警附加信息(位置类型:路线,");
                        }
                        ret.append("区域或路线ID:").append(BitOperator.hexToInt(data.substring(6, 16)));
                        int Direction = BitOperator.hexToInt(data.substring(16));
                        if (Direction == 0) {
                            ret.append("方向为进)");
                        } else if (Direction == 1) {
                            ret.append("方向为出)");
                        }
                        break;
                    case "13":
                        //路段行驶时间不足/过长报警附加信
                        ret.append("路段行驶时间不足/过长报警附加信息(路段ID:").append(BitOperator.hexToInt(data.substring(4, 12))).append("路段行驶时间:").append(BitOperator.hexToInt(data.substring(12, 20)));
                        int result = BitOperator.hexToInt(data.substring(20));
                        if (result == 0) {
                            ret.append("结果:不足)");
                        } else if (result == 1) {
                            ret.append("结果:过长)");
                        }
                        break;
                    case "14":
                        //1078协议视频报警
//                            gps.setVam(Long.parseLong(attachContent.substring(0,8),16));
//                        gps.SetAlarm(GpsAlarmType.storageUnitFailure);
//                        tmp = data.substring(4, (BitOperator.hexToInt(data.substring(2, 4))) * 2);
                        ret.append("存储单元故障报警:").append(BitOperator.hexToInt(data.substring(4, 12))).append(",");
                        break;
                    case "25":
                        //新北斗 扩展车辆信号状态位
                        tmp = data.substring(4, (BitOperator.hexToInt(data.substring(2, 4))) * 3);
                        String bin = BitOperator.hexToBin(tmp, 32);
                        if (Integer.parseInt(Character.toString(bin.charAt(31))) == 1)
                            ret.append("近光开,");
                        if (Integer.parseInt(Character.toString(bin.charAt(31 - 1))) == 1)
                            ret.append("远光开,");
                        if (Integer.parseInt(Character.toString(bin.charAt(31 - 2))) == 1)
                            ret.append("右转开，");
                        if (Integer.parseInt(Character.toString(bin.charAt(31 - 3))) == 1)
                            ret.append("左转开，");
                        if (Integer.parseInt(Character.toString(bin.charAt(31 - 4))) == 1)
                            ret.append("刹车开,");
                        if (Integer.parseInt(Character.toString(bin.charAt(31 - 5))) == 1)
                            ret.append("倒车开,");
                        if (Integer.parseInt(Character.toString(bin.charAt(31 - 6))) == 1)
                            ret.append("雾灯开,");
                        if (Integer.parseInt(Character.toString(bin.charAt(31 - 7))) == 1)
                            ret.append("示廓开,");
                        if (Integer.parseInt(Character.toString(bin.charAt(31 - 8))) == 1)
                            ret.append("喇叭信号开,");
                        if (Integer.parseInt(Character.toString(bin.charAt(31 - 9))) == 1)
                            ret.append("空调开,");
                        if (Integer.parseInt(Character.toString(bin.charAt(31 - 10))) == 1)
                            ret.append("空挡开,");
                        if (Integer.parseInt(Character.toString(bin.charAt(31 - 11))) == 1)
                            ret.append("缓速器正常,");
                        if (Integer.parseInt(Character.toString(bin.charAt(31 - 12))) == 1)
                            ret.append("ABS工作正常,");
                        if (Integer.parseInt(Character.toString(bin.charAt(31 - 13))) == 1)
                            ret.append("加热器工作正常,");
                        if (Integer.parseInt(Character.toString(bin.charAt(31 - 14))) == 1)
                            ret.append("离合器状态正常,");
                        break;
                    case "2A":
                        tmp = data.substring(4, 6);
                        String bin1 = BitOperator.hexToBin(tmp, 15);
                        if (Integer.parseInt(Character.toString(bin1.charAt(15))) == 1)
                            ret.append("深度休眠状态,");
                        if (Integer.parseInt(Character.toString(bin1.charAt(15 - 1))) == 1)
                            ret.append("休眠状态,");
                        break;
                    case "30":
                        //buty，无线通信网络信号强度  长度1
                        tmp = data.substring(4, 6);
                        ret.append("无限通信网络信号强度：").append(BitOperator.hexToInt(tmp));
                        break;
                    case "31":
                        //buty，GNSS定位卫星数   长度1
                        tmp = data.substring(4, 6);
                        ret.append("GNSS定位卫星数：").append(BitOperator.hexToInt(tmp));
                        break;
                    case "E0":
                        //油耗
                        //油耗类型
                        int OilConsumption = BitOperator.hexToInt(data.substring(4, 6));
                        if (OilConsumption == 0) {
                            ret.append("油耗类型:电阻式值:").append(BitOperator.hexToInt(data.substring(6, 10))).append(".").append(BitOperator.hexToInt(data.substring(10, 12)));
                        } else if (OilConsumption == 1) {
                            ret.append("油耗类型:电压式值:").append(BitOperator.hexToInt(data.substring(6, 8))).append(".").append(BitOperator.hexToInt(data.substring(8, 16)));
                        } else if (OilConsumption == 2) {
                            ret.append("油耗类型:液位值:").append(BitOperator.hexToInt(data.substring(4, 12))).append("mm,");
                        }
                        break;
                    case "E8":
                        //重量传感器值,当值为0xFFFF时表示没有重量回传
                        tmp = data.substring(4, (BitOperator.hexToInt(data.substring(2, 4))) * 2);
                        ret.append("传感器原始值：").append(BitOperator.hexToInt(tmp.substring(0, 4))).append(",传感器状态值：").append(tmp.substring(4, 6)).append(",顶灯状态：");
                        switch (tmp.substring(6, 8)) {
                            case "00":
                                ret.append("熄灭,");
                                break;
                            case "01":
                                ret.append("绿灯,");
                                break;
                            case "02":
                                ret.append("黄灯,");
                                break;
                            case "04":
                                ret.append("红灯,");
                                break;
                        }
                        ret.append("传感器速度：").append(BitOperator.hexToInt(tmp.substring(8, 10))).append(".").append(BitOperator.hexToInt(tmp.substring(10, 12))).append(",");
                        break;
                    case "EB":
                        //小书包 定位模式上报
                        int state = BitOperator.hexToInt(data.substring(6, 8));
                        if (state == 1) {
                            ret.append("当前为充电状态,剩余电量:").append(BitOperator.hexToInt(data.substring(4, 6)));
                        } else if (state == 2) {
                            ret.append("当前为未充电状态,剩余电量:").append(BitOperator.hexToInt(data.substring(4, 6)));
                        }
                        break;
                    case "EC":
                        /*
                        小书包
                        长度: 2 类型: WORD
                        第一个字节平台设置定位模式
                        1.基站定位； 2.普通定位； 3.高精度定位
                        第二个字节当前定位器定位状态
                        1：基站定位；2：WIFI定位； 3：GPS定位 4：高精度RTK
                        */
                        int Mode = BitOperator.hexToInt(data.substring(4, 6));
                        int LocationState = BitOperator.hexToInt(data.substring(6, 8));
                        if (Mode == 1) {
                            ret.append("定位模式:基站定位,");
                        } else if (Mode == 2) {
                            ret.append("定位模式:普通定位,");
                        } else if (Mode == 3) {
                            ret.append("定位模式:高精度定位,");
                        }

                        if (LocationState == 1) {
                            ret.append("定位状态:基站定位,");
                        } else if (LocationState == 2) {
                            ret.append("定位状态:WIFI定位,");
                        } else if (LocationState == 3) {
                            ret.append("定位状态:GPS定位,");
                        } else if (LocationState == 4) {
                            ret.append("定位状态:高精度RTK,");
                        }
                        break;
                    case "EF":
                        //小书包 电池电压
                        tmp = data.substring(4, 8);
                        ret.append("当前定位器电池电压:").append(BitOperator.hexToInt(tmp)).append("mV,");
                    case "E1":
                        ret.append("扩展信息E1未解析,");
                        break;
                    case "F1":
                        //油量传感器值
                        int OilStatus = BitOperator.hexToInt(data.substring(4, 6));
                        if (OilStatus == 0) {
                            ret.append("油量状态为实时数据,油量传感器读取值:").append(BitOperator.hexToInt(data.substring(6, 8)));
                        } else if (OilStatus == 1) {
                            ret.append("油量状态为快速增加").append(BitOperator.hexToInt(data.substring(6, 8)));
                        } else if (OilStatus == 2) {
                            ret.append("油量状态为快速减少").append(BitOperator.hexToInt(data.substring(6, 8)));
                        } else if (OilStatus == 3) {
                            ret.append("油量状态为平行震荡").append(BitOperator.hexToInt(data.substring(6, 8)));
                        }
                        break;
//                    case "64":
//                        //苏标协议 高级驾驶辅助系统报警信息
//                        tmp = data.substring(10, 12);
//                        String AlarmType = "";
//                        int FrontCarSpeed = 0;
//                        int FrontCarDistance = 0;
//                        String TmpDeviateType = data.substring(20, 22);
//                        String DeviateType = "";
//                        String ReasonSigntype = "";
//
//                        if (tmp == "01") {
//                            AlarmType = "前向碰撞报警";
//                            FrontCarSpeed = BitOperator.hexToInt(data.substring(16, 18));
//                            FrontCarDistance = BitOperator.hexToInt(data.substring(18, 20));
//                        }
//                        if (tmp == "02") {
//                            AlarmType = "车道偏离报警";
//                            FrontCarSpeed = BitOperator.hexToInt(data.substring(16, 18));
//                            FrontCarDistance = BitOperator.hexToInt(data.substring(18, 20));
//                            if (TmpDeviateType == "01") {
//                                DeviateType = "左侧偏离,";
//                            } else if (TmpDeviateType == "02") {
//                                DeviateType = "右侧偏离,";
//                            }
//                        }
//                        if (tmp == "03")
//                            AlarmType = "车距过近报警";
//                        if (tmp == "04") {
//                            AlarmType = "行人碰撞报警";
//                            FrontCarDistance = BitOperator.hexToInt(data.substring(18, 20));
//                        }
//                        if (tmp == "05")
//                            AlarmType = "频繁变道报警";
//                        if (tmp == "06") {
//                            AlarmType = "道路标识超限报警";
//                            tmp = data.substring(22, 24);
//                            if (tmp == "01") {
//                                ReasonSigntype = "限速标志,";
//                            } else if (tmp == "02") {
//                                ReasonSigntype = "限高标志,";
//                            } else if (tmp == "03") {
//                                ReasonSigntype = "限重标志";
//                            }
//                        }
//                        if (tmp == "07")
//                            AlarmType = "障碍物报警";
//                        if (tmp == "10") {
//                            AlarmType = "道路标志识别事件";
//                            tmp = data.substring(22, 24);
//                            if (tmp == "01") {
//                                ReasonSigntype = "限速标志,";
//                            } else if (tmp == "02") {
//                                ReasonSigntype = "限高标志,";
//                            } else if (tmp == "03") {
//                                ReasonSigntype = "限重标志";
//                            }
//                        }
//                        if (tmp == "11")
//                            AlarmType = "主动抓拍事件";
//
//                        String tmpAlarmLevel = data.substring(12, 14);
//                        String AlarmLevel = "";
//                        if (tmpAlarmLevel.equals(01)) {
//                            AlarmLevel = "一级报警";
//                        } else if (tmpAlarmLevel.equals(02)) {
//                            AlarmLevel = "二级报警";
//                        }
//
//
//                        if (DeviateType == "01") {
//                            DeviateType = "";
//                        } else if (DeviateType == "02") {
//                            DeviateType = "";
//                        }
//
//                        //车辆状态
//                        BitOperator.hexToInt(data.substring(60, 64));
//
//                        //报警标识号
//                        BitOperator.hexToInt(data.substring(64));
//
//                        Date gpsdate = TimeUtil.getDateByFormat(data.substring(48, 60), TimeUtil.dateFormatyyMMddHHmmss);
//                        ret += "高级驾驶辅助系统报警信息:(报警ID:" + BitOperator.hexToInt(data.substring(4, 8)) + "标志状态:"
//                                + BitOperator.hexToInt(data.substring(8, 10)) + ",报警/事件类型:" + AlarmType + "报警级别:"
//                                + AlarmLevel + "前车速度:" + BitOperator.hexToInt(data.substring(14, 16)) + "Km/h,前车/行人距离" +
//                                FrontCarSpeed + "Km/h,前车/行人距离:" + FrontCarDistance + "ms,偏离类型:" + DeviateType + "道路标志识别类型:"
//                                + ReasonSigntype + "道路标志识别数据:" + BitOperator.hexToInt(data.substring(24, 26)) + "车速:" +
//                                BitOperator.hexToInt(data.substring(26, 28)) + "Km/h,高程:" + BitOperator.hexToInt(data.substring(28, 32))
//                                + "m,纬度:" + BitOperator.hexToInt(data.substring(32, 40)) / 1000000.0 + "经度:" +
//                                BitOperator.hexToInt(data.substring(40, 48)) / 1000000.0 + "时间:" +
//                                TimeUtil.getStringByFormat(gpsdate, TimeUtil.dateFormatYMDHMS) + "车辆状态:暂时未解析,报警标识号:暂时未解析.";
//
//                        break;
//                    case "65":
//                        //苏标协议 驾驶员状态检测系统报警信息
//                        tmp = data.substring(14, 16);
//                        if (tmp == "01")
//                            ret += "疲劳驾驶报警,";
//                        if (tmp == "02")
//                            ret += "接打电话报警,";
//                        if (tmp == "03")
//                            ret += "抽烟报警,";
//                        if (tmp == "04")
//                            ret += "分神驾驶报警,";
//                        if (tmp == "05")
//                            ret += "驾驶员异常报警,";
//                        if (tmp == "10")
//                            ret += "自动抓拍事件,";
//                        if (tmp == "11")
//                            ret += "驾驶员变更事件,";
//                        break;
//                    case "66":
//                        //苏标协议 胎压检测系统报警信息
//                        tmp = data.substring(14, 16);
//                        if (tmp == "00")
//                            ret += "胎压,";
//                        if (tmp == "01")
//                            ret += "胎压过高报警,";
//                        if (tmp == "02")
//                            ret += "胎压过底报警,";
//                        if (tmp == "03")
//                            ret += "胎温过高报警,";
//                        if (tmp == "04")
//                            ret += "传感器异常报警,";
//                        if (tmp == "05")
//                            ret += "胎压不平衡报警,";
//                        if (tmp == "06")
//                            ret += "慢漏气报警,";
//                        if (tmp == "07")
//                            ret += "电池电量低报警,";
//                        break;
//                    case "67":
//                        //苏标协议 盲区检测系统报警信息
//                        tmp = data.substring(14, 16);
//                        if (tmp == "01")
//                            ret += "后方接近报警";
//                        if (tmp == "02")
//                            ret += "左侧后方接近报警";
//                        if (tmp == "03")
//                            ret += "右侧后方接近报警";
//                        break;
//
//                    case "6A":
//                        tmp = data.substring(14, 16);
//                        if (tmp == "01")
//                            ret += "车厢摄像头遮挡,";
//                        if (tmp == "02")
//                            ret += "货物检测未密闭(非传感器检测),";
//                        if (tmp == "03")
//                            ret += "货物检测异常举升（非传感器检测）,";
//                        if (tmp == "03")
//                            ret += "车厢摄像头角度偏离,";
//                        break;
//                    case "6B":
//                        tmp = data.substring(14, 16);
//                        if (tmp == "01")
//                            ret += "前方盲区报警,";
//                        if (tmp == "11")
//                            ret += "右侧盲区一级报警),";
//                        if (tmp == "12")
//                            ret += "右侧盲区二级报警,";
//                        if (tmp == "13")
//                            ret += "右侧盲区三级报警,";
//                        break;
                    default:
                        return ret.toString();
                }


//                }
                data = data.substring((BitOperator.hexToInt(data.substring(2, 4)) + 2) * 2);
            }
        }
        return ret + "。\n";
    }


    //驾驶员身份信息采集上报
    public static String DirverInfoUpLoad(String info) {
        String data = info.substring(26, 26 + info.length() - 30);
        int Len = BitOperator.hexToInt(data.substring(0, 2));
        String DriverName = BitOperator.hexStringToString(data.substring(2, 2 + Len * 2));
        DriverName = DriverName.replace("\0", "");
        String Status = "驾驶员姓名：" + DriverName + "|";
        String IdentityCardNumber = BitOperator.hexStringToString(data.substring(2 + Len * 2, (2 + Len * 2) + 40));
        IdentityCardNumber = IdentityCardNumber.replace("\0", "");
        Status = Status + "驾驶员身份证编码：" + IdentityCardNumber + "|";
        String QualificationCertificate = BitOperator.hexStringToString(data.substring(2 + Len * 2 + 40, (2 + Len * 2 + 40) + 80));
        QualificationCertificate = QualificationCertificate.replace("\0", "");
        Status = Status + "从业资格证编码：" + QualificationCertificate + "|";
        int n = 2 + Len * 2 + 40 + 80;
        Len = BitOperator.hexToInt(data.substring(n, n + 2));
        String LicenceIssuingAuthority = BitOperator.hexStringToString(data.substring(n + 2, (n + 2) + Len * 2));
        LicenceIssuingAuthority = LicenceIssuingAuthority.replace("\0", "");
        Status = Status + "发证机关名称：" + LicenceIssuingAuthority;
        return Status;
    }

    //报警附件信息消息
    public static String AlarmAnnexMessage(String info) {
        String ret = "";
        String data = info.substring(26, 26 + info.length() - 30);
        //终端ID
        ret += "终端ID:" + BitOperator.hexToInt(data.substring(0, 14));
        //报警标识号
        String Alarmsign = BitOperator.hexStringToString(data.substring(14, 46));
        //报警标识号:时间
        String Time = Alarmsign.substring(28, 40);
        Date SyncTimeDate = TimeUtil.getDateByFormat(Time, TimeUtil.dateFormatyyMMddHHmmss);
        ret += "报警标识号:(终端编号:" + BitOperator.hexToInt(Alarmsign.substring(14, 28)) + "时间:" + TimeUtil.getStringByFormat(SyncTimeDate, TimeUtil.dateFormatYMDHMS) +
                "序号:" + BitOperator.hexToInt(Alarmsign.substring(40, 41)) + "附加数量:" + BitOperator.hexToInt(Alarmsign.substring(41, 43)) + "),";
        //报警编号
        String AlarmNumber = data.substring(46, 110);
        ret += "报警编号:" + AlarmNumber + ",";
        if (BitOperator.hexToInt(data.substring(110, 112)) == '0') {
            ret += "信息类型:正常报警文件信息,附件数量:" + BitOperator.hexToInt(data.substring(112, 114)) + ",";
        } else if (BitOperator.hexToInt(data.substring(110, 112)) == '1') {
            ret += "信息类型:正常报警文件信息,附件数量:" + BitOperator.hexToInt(data.substring(112, 114)) + ",";
        }
        return ret;
    }

    //文件上传完成消息
    public static String FileUploadComplete(String info) {
        String ret = "";
        String data = info.substring(26, 26 + info.length() - 30);
        ret += "文件名称长度:" + BitOperator.hexToInt(data.substring(0, 2)) + "文件名称:" +
                BitOperator.hexStringToString(data.substring(2, 2 + BitOperator.hexToInt(data.substring(0, 2))));
        int FileType = BitOperator.hexToInt(data.substring(2 + BitOperator.hexToInt(data.substring(0, 2)), 4 + BitOperator.hexToInt(data.substring(0, 2))));
        if (FileType == '0') {
            ret += "文件类型:图片";
        } else if (FileType == '1') {
            ret += "文件类型:音频";
        } else if (FileType == '2') {
            ret += "文件类型:视频";
        } else if (FileType == '3') {
            ret += "文件类型:文本";
        } else if (FileType == '4') {
            ret += "文件类型:其它";
        }
        ret += "文件大小:" + BitOperator.hexToInt(data.substring(4 + BitOperator.hexToInt(data.substring(0, 2)), 6 + BitOperator.hexToInt(data.substring(0, 2))));
        return ret;
    }


    //人脸库同步
    public static String FaceDataBaseSet(String info) {
        String data = info.substring(26, 26 + info.length() - 30);
        StringBuilder result = new StringBuilder();
        int setType = BitOperator.hexToInt(data.substring(0, 2));
        int FaceNum = BitOperator.hexToInt(data.substring(2, 2 + 4));
        result.append("设置类型：").append(setType).append("人脸数量：  ").append(FaceNum);
        int index = 6;
        for (int i = 0; i < FaceNum; i++) {
            int faceIDLength = BitOperator.hexToInt(data.substring(index, index + 2));
            index += 2;
            String faceID = BitOperator.hexStringToString(data.substring(index, index + faceIDLength * 2));
            index = faceIDLength * 2 + index;
            int cercardLength = BitOperator.hexToInt(data.substring(index, index + 2));
            index += 2;
            String cerCardSerial = BitOperator.hexStringToString(data.substring(index, index + cercardLength * 2));
            index = cercardLength * 2 + index;
            int faceAdressType = BitOperator.hexToInt(data.substring(index, index + 2));
            index += 2;
            int urlLength = BitOperator.hexToInt(data.substring(index, index + 2));
            index += 2;
            String url = BitOperator.hexStringToString(data.substring(index, index + (urlLength * 2)));
            index = urlLength * 2 + index;
            int picSource = BitOperator.hexToInt(data.substring(index, index + 2));
            String tmp = "人脸id：" + faceID + "，资格证号：" + cerCardSerial + "，下载地址类型：" +
                    faceAdressType + "，Url:" + url + "，对比来源：" + picSource + "" + "，";
            result.append(tmp);
        }
        return result.toString();
    }

    //人脸对比结果下发
    public static String FaceContrastResult(String info) {
        String ret = "";
        String data = info.substring(26, 26 + info.length() - 30);
        //比对结果

        return ret;
    }

    //根据指令ID获取中文描述
    public static String GetDescriptionByCommandID(String CommandID) {
        String ret = "";
        switch (CommandID) {
            case "8001":
                ret = "平台通用应答";
                break;
            case "0002":
                ret = "终端心跳";
                break;
            case "0100":
                ret = "终端注册";
                break;
            case "8100":
                ret = "终端注册应答";
                break;
            case "0003":
                ret = "终端注销";
                break;
            case "0102":
                ret = "终端鉴权";
                break;
            case "0200":
                ret = "位置信息汇报";
                break;
            case "8103":
                ret = "设置终端参数";
                break;
            case "8104":
                ret = "查询终端参数";
                break;
            case "0104":
                ret = "查询终端应答参数";
                break;
            case "8105":
                ret = "终端控制";
                break;
            case "8201":
                ret = "位置信息查询";
                break;
            case "0201":
                ret = "位置信息查询应答";
                break;
            case "8202":
                ret = "临时位置跟踪控制";
                break;
            case "8300":
                ret = "文本信息下发";
                break;
            case "8301":
                ret = "事件设置";
                break;
            case "0301":
                ret = "事件报告";
                break;
            case "8302":
                ret = "提问下发";
                break;
            case "0302":
                ret = "提问应答";
                break;
            case "8303":
                ret = "信息点播菜单设置";
                break;
            case "0303":
                ret = "信息点播/取消";
                break;
            case "8304":
                ret = "信息服务";
                break;
            case "8400":
                ret = "电话回拨";
                break;
            case "8401":
                ret = "设置电话本";
                break;
            case "8500":
                ret = "车辆控制";
                break;
            case "0500":
                ret = "车辆控制应答";
                break;
            case "8600":
                ret = "设置圆形区域";
                break;
            case "8601":
                ret = "删除圆形区域";
                break;
            case "8602":
                ret = "设置矩形区域";
                break;
            case "8603":
                ret = "删除矩形区域";
                break;
            case "8604":
                ret = "设置多边形区域";
                break;
            case "8605":
                ret = "删除多边形区域";
                break;
            case "8606":
                ret = "设置路线";
                break;
            case "8607":
                ret = "删除路线";
                break;
            case "8700":
                ret = "数据采集命令";
                break;
            case "8701":
                ret = "行驶记录参数下传命令";
                break;
            case "0701":
                ret = "电子运单上报";
                break;
            case "0702":
                ret = "驾驶员身份信息采集上报";
                break;
            case "0800":
                ret = "多媒体事件信息上传";
                break;
            case "8800":
                ret = "多媒体数据上传应答";
                break;
            case "0801":
                ret = "多媒体数据上传";
                break;
            case "8801":
                ret = "摄像头立即拍照命令";
                break;
            case "8802":
                ret = "存储多媒体数据检索";
                break;
            case "0802":
                ret = "存储多媒体数据检索应答";
                break;
            case "8803":
                ret = "存储多媒体数据上传命令";
                break;
            case "8804":
                ret = "录音开始命令";
                break;
            case "8900":
                ret = "数据下行透传";
                break;
            case "0900":
                ret = "数据上行透传";
                break;
            case "0901":
                ret = "数据压缩上报";
                break;
            case "8A00":
                ret = "平台RSA公钥";
                break;
            case "0A00":
                ret = "终端RSA公钥";
                break;
            case "0704":
                ret = "定位数据批量上传";
                break;
            case "0xF114":
                ret = "管控开关定义";
                break;
            case "0xF115":
                ret = "管控开关查询";
                break;
            case "0x860D":
                ret = "新增多边形区域";
                break;
            case "0x860E":
                ret = "删除多边形区域";
                break;
            case "0x8610":
                ret = "新增线路";
                break;
            case "0x8611":
                ret = "删除线路";
                break;
            case "0x8621":
                ret = "禁运指令下发";
                break;
            ///升级版本后新加
            case "0x1210":
                ret = "报警附件信息消息";
                break;
            case "0x1212":
                ret = "文件上传完成消息";
                break;
            case "0x0702":
                ret = "采集驾驶员身份信息数据";
                break;
            case "0x0704":
                ret = "盲点补传";
                break;
            case "0x8624":
                ret = "黑车稽查指令下发";
                break;
            case "0x8E20":
                ret = "人脸对比结果下发";
                break;
            case "0x8E21":
                ret = "人脸库下发";
                break;
            default:
                ret = CommandID;
                break;
        }
        return ret;
    }
}
